﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Security.Cryptography;
using System.Windows.Forms;
using System.Collections;

namespace dupfiledel
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void listBox1_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
            {
                string[] array = (string[])e.Data.GetData(DataFormats.FileDrop);
                foreach (string item in array)
                {
                    (sender as ListBox).Items.Add(item);
                }
            }
        }

        private void listBox1_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.All;
        }

        private void listBox1_DragOver(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.All;
        }
        public static string ByteToArray(byte[] array)
        {
            string text = "";
            for (int i = 0; i < array.Length; i++)
            {
                text += string.Format("{0:X2}", array[i]);
            }
            return text;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (this.listBox1.Items.Count == 0)
            {
                return;
            }
            string[] a = new string[listBox1.Items.Count];

            ArrayList al = new ArrayList();
            for (int i = 0; i < listBox1.Items.Count; i++)
            {
                string text = (string)this.listBox1.Items[i];
                if (!al.Contains(text))
                {
                    al.Add(text);

                }

            }
            string[] b = new string[al.Count];
            int kk = 0;
            foreach (string s in al)
            {
                b[kk] = s;
                kk++;

            }
            //string[] b = new string[al.Count];

            string[] array = new string[al.Count];
            string[] array2 = new string[al.Count];
            for (int i = 0; i < al.Count; i++)
            {
                string text = b[i];
                array[i] = text;
                FileStream fileStream = File.OpenRead(text);
                SHA256 sha = SHA256.Create();
                byte[] array3 = sha.ComputeHash(fileStream);
                array2[i] = Form1.ByteToArray(array3);
                fileStream.Close();
            }
            int num = 0;
            for (int j = 0; j < al.Count; j++)
            {
                if (!array2[j].Equals(""))
                {
                    for (int k = j + 1; k < al.Count; k++)
                    {
                        if (array2[j].Equals(array2[k]))
                        {
                            File.Delete(array[k]);
                            num++;
                            array2[k] = "";
                        }
                    }
                }
            }
            while (this.listBox1.Items.Count > 0)
            {
                this.listBox1.Items.RemoveAt(this.listBox1.Items.Count - 1);
            }
            int num2 = al.Count - num;
            MessageBox.Show(string.Concat(new object[]
			{
				al.Count,
				" - ",
				num,
				" == ",
				num2
			}));
        }
    }
}
